#!/bin/bash

packages_dir=/usr/local/src
app_install_dir=/usr/local


# 批量解压所有压缩包
unzip_packages() {
  cd "${1}"
  for package in ls *tar.gz*; do
    tar -zvxf $package
    make_app_dir $package
  done

  for package in ls *tar.bz2*; do
    tar -jvxf $package
    make_app_dir $package
  done
}

# 批量创建安装的目录
make_app_dir() {
  if [[ ${1} == *-* ]]; then
    # 获取以-分割的单词
    mkdir -p ${app_install_dir}/${package%%-*}
    echo "${app_install_dir}/${package%%-*}"
  else
    mkdir -p ${app_install_dir}/${package%%.*}
    ecgo "${app_install_dir}/${package%%.*}"
  fi
}


# 解压所有安装包并创建目录
yum install -y bzip2
unzip_packages $packages_dir